const BASE_API = 'https://xueyouwangxiao.com/WebService.asmx'

export function post (url, data) {
  return new Promise((resolve, reject) => {
    wx.request({
      url: BASE_API + url,
      method: 'POST',
      data,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success (response) {
        const res = response.data
        console.log('res', res)
        if (res.errcode === '0') {
          resolve(res)
        } else {
          reject(res)
        }
      },
      fail (error) {
        console.log('error', error)
      }
    })
  })
}

export function get (url, data) {
  return new Promise((resolve, reject) => {
    wx.request({
      url: BASE_API + url,
      method: 'GET',
      data,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success (response) {
        const res = response.data
        console.log('res', res)
        if (res.errcode === '0') {
          resolve(res)
        } else {
          reject(res)
        }
      },
      fail (error) {
        console.log('error', error)
      }
    })
  })
}
// export function getLoginCode () {
//   return new Promise((resolve, reject) => {
//     wx.login({
//       success: (res) => {
//         if (res.errMsg === 'login:ok') {
//           resolve(res.code)
//         }
//       }
//     })
//   })
// }
